unit U_FiltroContasImob;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, FMTBcd, DB, SqlExpr, Mask,
  JvExMask, JvToolEdit, JvMaskEdit, JvCheckedMaskEdit, JvDatePickerEdit;

type
  TF_FiltroContasImob = class(TForm)
    pnl4: TPanel;
    btnBtnOk: TBitBtn;
    btnBtnCancel: TBitBtn;
    pnl2: TPanel;
    lbl2: TLabel;
    edtForCli: TEdit;
    btn1: TBitBtn;
    pnl6: TPanel;
    lbl5: TLabel;
    cbbCaixa: TComboBox;
    sForma: TSQLDataSet;
    sFormaID_FORMAPGTO: TIntegerField;
    sFormaDESC_FORMAPGTO: TStringField;
    sCaixa: TSQLDataSet;
    sCaixaID_CAIXA: TIntegerField;
    sCaixaDESC_CAIXA: TStringField;
    pnl1: TPanel;
    lbl1: TLabel;
    cbbFormaPgto: TComboBox;
    pnl5: TPanel;
    lbl4: TLabel;
    cbbStatus: TComboBox;
    pnl3: TPanel;
    lbl3: TLabel;
    DtVencIni: TJvDatePickerEdit;
    lbl6: TLabel;
    DtVencFim: TJvDatePickerEdit;
    pnl7: TPanel;
    lbl7: TLabel;
    lbl8: TLabel;
    DtPagIni: TJvDatePickerEdit;
    DtPagFim: TJvDatePickerEdit;
    procedure btn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnBtnOkClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_FiltroContasImob: TF_FiltroContasImob;

implementation

uses UDM, uProcurar;

{$R *.dfm}

procedure TF_FiltroContasImob.btn1Click(Sender: TObject);
begin
  if (dm.vTipo = 'Despesa') then  // Fornecedor
  begin
    fProcurar:=TfProcurar.Create(self,dm.proc_funcionario);
    try
      fProcurar.BtnProcurar.Click;
      fProcurar.EvDBFind1.DataField := 'NOME';
      if fProcurar.ShowModal=mrOk then
        edtForCli.Text := dm.proc_funcionarioNOME.AsString;
    finally
      dm.proc_funcionario.Close;
      fProcurar.Free;
    end;
  end
  else  // Cliente
  begin
    fProcurar:=TfProcurar.Create(self,dm.proc_cliente);
    try
      fProcurar.BtnProcurar.Click;
      fProcurar.EvDBFind1.DataField := 'NOME';
      if fProcurar.ShowModal=mrOk then
        edtForCli.Text := dm.proc_clienteNOME.AsString;
    finally
      dm.proc_cliente.Close;
      fProcurar.Free;
    end;
  end;
end;

procedure TF_FiltroContasImob.FormShow(Sender: TObject);
begin
  if (DM.vTipo = 'Receita') then
    lbl2.Caption := 'Cliente'
  else
    lbl2.Caption := 'Fornecedor';

   if (not sCaixa.Active) then
      sCaixa.Open;
   sCaixa.First;
   while (not sCaixa.Eof) do
   begin
     cbbCaixa.Items.Add(sCaixaDESC_CAIXA.AsString);
     sCaixa.Next;
   end;
   sCaixa.Close;
   if (not sForma.Active) then
      sForma.Open;
   sForma.First;
   while (not sForma.Eof) do
   begin
     cbbFormaPgto.Items.Add(sFormaDESC_FORMAPGTO.AsString);
     sForma.Next;
   end;
   sForma.Close;
   edtForCli.Text := '';
   cbbCaixa.Text := '';
   cbbFormaPgto.Text := '';
   cbbStatus.Text := '';
end;

procedure TF_FiltroContasImob.btnBtnOkClick(Sender: TObject);
begin
  // Cliente ou Fornecedor
  if (edtForCli.Text <> '') then
    dm.TextoForCli := edtForCli.Text;
  // Caixa
  if (cbbCaixa.Text <> '') then
    dm.TextoCaixa := cbbCaixa.Text;
  // Forma de Pgto
  if (cbbFormaPgto.Text <> '') then
    dm.TextoFormapgto := cbbFormaPgto.Text;
  // Status
  if (cbbStatus.Text <> '') then
    dm.TextoStatus := cbbStatus.Text;
  // Vencimento
  if (DtVencIni.Text <> '') then
    dm.vDtaIni := DtVencIni.Date;
  if (DtVencFim.Text <> '') then
    dm.vDtaFim := DtVencFim.Date;
  // Pagamento
  if (DtPagIni.Text <> '') then
    dm.vDtaPini := DtPagIni.Date;
  if (DtPagFim.Text <> '') then
    dm.vDtaPfim := DtPagFim.Date;
end;

end.
